﻿using MyConvert;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyExe.Models
{
    /// <summary>
    /// 绑定对象基类
    /// </summary>
    public class BaseUIModel : INotifyPropertyChanged
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public virtual T ToModel<T>() where T : new()
        {
            T t = new T();
            ModelConvert.CopyValue(this, t);
            return t;
        }

        #region  通知界面更改

        /// <summary>
        /// 定义更改属性时引发的事件
        /// </summary>
        public event PropertyChangedEventHandler? PropertyChanged;

        /// <summary>
        /// 通知
        /// </summary>
        /// <param name="propertyName">属性参数</param>
        public virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion 通知界面更改
    }

}
